#include <stdio.h>
#include <malloc.h>

void fatal_error(char *str) {
}

typedef struct node *node_ptr;

struct node {
    //? element_type
    int element;
    node_ptr next;
};
typedef node_ptr LIST;
typedef node_ptr position;

//? LIST is the sentinel
int is_empty(LIST L) {
    return (L->next == NULL);
}

//? position is the last
int is_last(position p, LIST L) {
    return (p->next == NULL);
}

//? L is the starting node, normally is the sentinel
position find(int x, LIST L) {
    position p;
    p = L->next;
    while ((p != NULL) && (p->element != x)) {
        p = p->next;
    }
    return p;
}

//? L is the starting node, normally is the sentinel
position find_previous(int x, LIST L) {
    position p;
    p = L;
    while ((p->next != NULL) && (p->next->element != x))
        p = p->next;
    return p;
}

void delete(int x, LIST L) {
    position p, tmp_cell;
    p = find_previous(x, L);
    if (p->next != NULL) {
        //? the x
        tmp_cell = p->next;
        //? x->next=y, p->next=y
        p->next = tmp_cell->next;
        free(tmp_cell);
    }
}

void insert(int x, LIST L, position p) {
    position tmp_cell;
    tmp_cell = (position) malloc(sizeof(struct node));
    if (tmp_cell == NULL) {
        fatal_error("Out of spacee!!!");
    } else {
        //? after insert // if want insert previous, need find_previous p->element, and then pointer tmp_cell
        tmp_cell->element = x;
        tmp_cell->next = p->next;
        p->next = tmp_cell;
    }
}

//? assume L is the header, sentinel
void delete_list(LIST L) {
    position p, tmp;
    p = L->next;
    L->next = NULL;
    while (p != NULL) {
        tmp = p->next;
        free(p);
        p = tmp;
    }
}


int main() {
    printf("Hello, World!\n");
    return 0;
}
